#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

const int N = 100010;

int B[N], S[N];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    while (n -- )
    {
        char op[2];
        int p, q;
        scanf("%s%d%d", op, &p, &q);
        if (*op == 'B') B[p] += q;
        else S[p] += q;
    }
    int k = 0;
    for (int i = 0, j = 0; i < N && j < m; i ++ )
        if (S[i])
        {
            j ++ ;
            k = i;
        }

    for (int i = k; i >= 0; i -- )
        if (S[i])
            printf("S %d %d\n", i, S[i]);

    for (int i = N - 1, j = 0; i >= 0 && j < m; i -- )
        if (B[i])
        {
            printf("B %d %d\n", i, B[i]);
            j ++ ;
        }

    return 0;
}